import Vue from 'vue'

import 'normalize.css/normalize.css'// A modern alternative to CSS resets

import Element from 'element-ui'
// import 'element-ui/lib/theme-chalk/index.css'
import './styles/element-variables.scss'

import '@/styles/index.scss' // global css

import App from './App'
import router from './router'
import store from './store'

import i18n from './lang' // Internationalization
import './icons' // icon
import './errorLog'// error log
import './permission' // permission control
import './mock' // simulation data
// 引用全局组件
import '@/components/'
import './common/plugins/svgIcon/index' // icon

import * as filters from './filters' // global filters
import {
  isLogin,
  login
} from './utils/login.js'

import Vant from 'vant'
import 'vant/lib/index.css'
Vue.use(Vant)

Vue.use(Element, {
  size: 'mini', // set element-ui default size
  i18n: (key, value) => i18n.t(key, value)
})

// register global utility filters.
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})
Vue.prototype.getUserElementRule = (code) => {
  return store.getters.elements && store.getters.elements.indexOf(code) >= 0
}

Vue.config.productionTip = false

// 判断是否登录
if (isLogin()) {
  new Vue({
    el: '#app',
    router,
    store,
    i18n,
    render: h => h(App)
  })
} else {
  login()
    .then(() => {
      new Vue({
        el: '#app',
        router,
        store,
        i18n,
        render: h => h(App)
      })
    })
    .catch(() => {})
}
